﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;

namespace Lemon.Blog.Blazor.Helper
{
    public static class ClassToDic<T>
    {
        public static Dictionary<string, string> ConvertClassToDic(T obj)
        {
            PropertyInfo[] prop = obj.GetType().GetProperties((BindingFlags.Public | BindingFlags.Instance));
            Dictionary<string, string> dic = new Dictionary<string, string>();
            foreach (var item in prop)
            {
                if (item.GetValue(obj) != null)
                    dic.Add(item.Name, item.GetValue(obj).ToString());
            }
            return dic;
        }
    }
}
